package com.lmpop.trade.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.lmpop.frame.SysMap;
import com.lmpop.trade.verification.VerificationInfo;

public class VerificationUtil
{
  private static VerificationInfo verificationInfo = new VerificationInfo();

  private static int verificationTime = 5;

  public boolean isVerificationSuccess(String user_name, String type, String target)
  {
    boolean isVerification = false;
    SysMap sysMap = new SysMap();
    sysMap.put("verification_type", type);
    sysMap.put("verification_target", target);
    sysMap.put("verification_user", user_name);
    List list = verificationInfo.getVerificationInfo(sysMap);

    if ((list != null) && (list.size() > 0)) {
      Map map = (Map)list.get(0);
      String verification_state = map.get("verification_state").toString();
      String verification_time = map.get("verification_time").toString();

      if ((map != null) && (verification_state != null) && (verification_state.equals("1"))) {
        isVerification = true;
      }
    }

    return isVerification;
  }

  public long getNowToVerificationSpan(String verification_time)
  {
    SimpleDateFormat simDf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    long verificationTimef = 0L;

    long newTime = System.currentTimeMillis();
    try
    {
      Date date = simDf.parse(verification_time);

      Calendar c = Calendar.getInstance();
      c.setTimeInMillis(date.getTime());
      c.add(12, verificationTime);
      verificationTimef = c.getTimeInMillis();
    } catch (ParseException e) {
      e.printStackTrace();
    }
    return verificationTimef - newTime;
  }

  public static void main(String[] args) {
    VerificationUtil verificationInfo = new VerificationUtil();
    boolean bl = verificationInfo.isVerificationSuccess("1Ij8P5K6Kt0o5M1", "2", "945498415@qq.com");
    System.out.print(bl);
  }

  public static int getVerificationTime() {
    return verificationTime;
  }
}